package com.accountbooks.justin;

import android.content.Context;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;

public class DBHelper extends SQLiteOpenHelper {
	
		//.db 扩展名不能漏
	 	private static final String DATABASE_NAME = "AccountBooks.db";  
	    private static final int DATABASE_VERSION = 1;  
	    
		//SQLiteOpenHelper的子类必须有构造函数
	    public DBHelper(Context context) {
			super(context, DATABASE_NAME, null, DATABASE_VERSION);
		}
	    
		public DBHelper(Context context, String name, CursorFactory factory, int version, DatabaseErrorHandler errorHandler) {
			super(context, DATABASE_NAME, factory, DATABASE_VERSION, errorHandler);
		}

		public DBHelper(Context context, String name, CursorFactory factory, int version) {
			super(context, DATABASE_NAME, factory, DATABASE_VERSION);
		}
		
		//该方法在第一次创建数据库时执行，实际上是第一次得到SQLiteDatabase对象时执行
		@Override
		public void onCreate(SQLiteDatabase db) {
			db.execSQL("CREATE TABLE Account_Type " + 
								"(Type_ID INTEGER PRIMARY KEY AUTOINCREMENT, " +
								"Parent_Type_ID INTEGER, " +
								"Type_Name TEXT, " +
								"Created_On TEXT, " +
								"Modified_On TEXT)");
			
			db.execSQL("CREATE TABLE IF NOT EXISTS Account_Detail " + 
								"(Detail_ID INTEGER PRIMARY KEY AUTOINCREMENT, " +
								"Type_ID INTEGER, " +
								"Spend_Amount REAL, " +
								"Remark_Info TEXT, " +
								"Created_On TEXT, " +
								"Modified_On TEXT)");
		}

		//该方法在数据库对象被更新时执行
		@Override
		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
			

		}
}
